//
//  DetailsView.swift
//  jiweiapp
//
//  Created by Kin Wong on 15/8/14.
//  Copyright (c) 2015年 Kin Wong. All rights reserved.
//

import UIKit
import Foundation

class DetailsView: UIViewController {
    
    var itemString: String?
    var itemDetail: String?
    var temp1:[String] = []
    var temp2:[String] = []
    var xmlData = XMLAnalyser()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let accpetbtn = UIBarButtonItem(title: "接受", style: UIBarButtonItemStyle.Plain, target: self, action: "accept")
        
        self.view.backgroundColor = UIColor.whiteColor()
        self.navigationItem.rightBarButtonItem = accpetbtn
        
        var name = UILabel(frame: CGRectMake(10, 80, 60, 30))
        var detail = UILabel(frame: CGRectMake(10, 100, 300, 30))
        var title = UILabel(frame: CGRectMake(80, 80, CGRectGetWidth(self.view.bounds)-90, 30))
        var detailInfo = UITextView(frame: CGRectMake(10, 130, CGRectGetWidth(self.view.bounds)-20, 300))
        name.text = "任务："
        name.textColor = UIColor.blackColor()
        detail.text = "详细信息："
        detail.textColor = UIColor.blueColor()
        title.text = itemString
        title.textColor = UIColor.blackColor()
        detailInfo.text = itemDetail
        detailInfo.textColor = UIColor.brownColor()
        detailInfo.layer.borderWidth = 0
        detailInfo.dataDetectorTypes = UIDataDetectorTypes.PhoneNumber
        detailInfo.editable = false
        
        detail.numberOfLines = 10
        
        self.view.addSubview(name)
        self.view.addSubview(detail)
        self.view.addSubview(title)
        self.view.addSubview(detailInfo)
        
        // Do any additional setup after loading the view.
    }
    
    func accept() {
        (self.temp1, self.temp2) = xmlData.readLocalXML("Saved.xml")
        self.temp1.insert(self.itemString!, atIndex: 0)
        self.temp2.insert(self.itemDetail!, atIndex: 0)
        xmlData.writeLocalXML("Saved.xml", titles: self.temp1, details: self.temp2)
        self.navigationController?.popToRootViewControllerAnimated(true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
